package com.itheima.service.impl;

import com.itheima.mapper.ClazzMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ClazzService;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private ClazzMapper clazzMapper;

    /**
     * 性别人数统计
     * @return
     */
    @Override
    public List<Map> getEmpGenderData() {

        return empMapper.countEmpGenderData();
    }

    /**
     * 职位人数统计
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
     List<Map<String,Object>> list= empMapper.countEmpJobData();
        //一行数据(字段--->字段值)----->一个对象(属性--->属性值)
        // 一行数据(字段--->字段值)---一个map对象(key(字段名称)---->value(岗位名称岗位数量))

        List<Object> jobList = list.stream().map(dataMap -> {
           return dataMap.get("pos");
        }).toList();
        List<Object> dataList = list.stream().map(dataMap -> {
            return dataMap.get("total");
        }).toList();
        return new JobOption(jobList,dataList);
    }


    /**
     * 学生学历统计
     * @return
     */
    @Override
    public List<Map> getstudentDegreeData() {
        return clazzMapper.coutStudentDegreeData();
    }

    /**
     * 班级人数统计
     * @return
     */
    @Override
    public ClazzOption getCLazz() {
    List<Map<String,Object>>  list = clazzMapper.countClazzCountData();

        List<Object> clazzList = list.stream().map(dataMap -> {
            return dataMap.get("pos");//获取pos字段
        }).toList();
        List<Object> dataList = list.stream().map(dataMap -> {
            return dataMap.get("total");//获取total字段
        }).toList();
        return new ClazzOption(clazzList,dataList);
    }


}
